//
//  ProductDetailHeader.swift
//  Nahuo
//
//  Created by zang qilong on 2017/5/17.
//  Copyright © 2017年 zang qilong. All rights reserved.
//

import UIKit
import FSPagerView
import YYWebImage

class ProductDetailHeader: UIView {
    var imagesURLStrings:[String] = [String]()
   
    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var descripleLabel: UILabel!
    @IBOutlet weak var discountPrice: UILabel!
    @IBOutlet weak var recommandLabel: UILabel!
    @IBOutlet weak var bannerView: FSPagerView! {
        didSet {
            self.bannerView.register(FSPagerViewCell.self, forCellWithReuseIdentifier: "cell")
        }
    }
    
    func setupHeader(model:Product) {
        nameLabel.text = model.name!
        discountPrice.text = "¥\(model.tradePrice!)"
        recommandLabel.text = "¥\(model.retailPrice!)"
        
        if let imageArray = model.imgs {
            imagesURLStrings = imageArray
        }
        self.bannerView.reloadData()
    }

}

extension ProductDetailHeader:FSPagerViewDataSource {
    func numberOfItems(in pagerView: FSPagerView) -> Int {
        return imagesURLStrings.count
    }
    
    func pagerView(_ pagerView: FSPagerView, cellForItemAt index: Int) -> FSPagerViewCell {
        let cell = pagerView.dequeueReusableCell(withReuseIdentifier: "cell", at: index)
        cell.imageView?.yy_setImage(with: URL(string: imagesURLStrings[index]), options: .progressiveBlur)

        return cell
    }
}
